package com.onlineMIS.ORM.DAO.headQ.barCodeGentor;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.onlineMIS.ORM.DAO.BaseDAO;
import com.onlineMIS.ORM.entity.headQ.barcodeGentor.ProductBarcodePic;
import com.onlineMIS.common.Common_util;
import com.onlineMIS.filter.SystemParm;

@Repository
public class ProductBarcodePicDaoImpl extends BaseDAO<ProductBarcodePic> {



	
	/**
	 * 根据pbId查询条码图片路径
	 * @param pbId
	 * @return
	 */
	public String getPicPath(int pbId,int type) {
		DetachedCriteria pCriteria = DetachedCriteria.forClass(ProductBarcodePic.class);
		
		pCriteria.add(Restrictions.eq("pbId", pbId));
		
		if (type != Common_util.ALL_RECORD)
		     pCriteria.add(Restrictions.eq("type", type));
		
		List<ProductBarcodePic> list = this.getByCritera(pCriteria, true);
		if (list.size() != 0) {
			return list.get(0).getPicPath();
		}else {
			return null;
		}
	}
	

	
	/**
	 * 根据pbId查询条码平面图 小图路径
	 * @param pbId
	 * @return
	 */
	public String getPicsURLPath(int pbId,int type) {
		DetachedCriteria pCriteria = DetachedCriteria.forClass(ProductBarcodePic.class);
		
		pCriteria.add(Restrictions.eq("pbId", pbId));
		pCriteria.add(Restrictions.eq("type", type));
		
		List<ProductBarcodePic> list = this.getByCritera(pCriteria, true);
		if (list.size() != 0) {
			return SystemParm.getQxPicURLHead() + list.get(0).getPicsPath().replaceAll("\\\\", "/");
		}else {
			return null;
		}
	}
	
	/**
	 * 根据条码查询图片 小图
	 * @param pbId
	 * @return
	 */
	public String getURLPicsPathByBarcode(String barcode,int type) {
			
		DetachedCriteria pCriteria = DetachedCriteria.forClass(ProductBarcodePic.class);
		
		pCriteria.add(Restrictions.eq("barcode", barcode));
		     pCriteria.add(Restrictions.eq("type", type));
				
		List<ProductBarcodePic> list = this.getByCritera(pCriteria, true);
		if (list.size() != 0) {			
			return SystemParm.getQxPicURLHead() + list.get(0).getPicsPath().replaceAll("\\\\", "/");
		}else {
			return null;
		}
	}
	/**
	 * 根据条码查询图片 大图
	 * @param pbId
	 * @return
	 */
	public String getURLPathByBarcode(String barcode,int type) {
			
		DetachedCriteria pCriteria = DetachedCriteria.forClass(ProductBarcodePic.class);
		
		pCriteria.add(Restrictions.eq("barcode", barcode));
		if (type != Common_util.ALL_RECORD)
		     pCriteria.add(Restrictions.eq("type", type));
				
		List<ProductBarcodePic> list = this.getByCritera(pCriteria, true);
		if (list.size() != 0) {			
			return SystemParm.getQxPicURLHead() + list.get(0).getPicPath().replaceAll("\\\\", "/");
		}else {
			return null;
		}
	}
	
}
